const {getTouchData: getTouchData} = require("../../../utils/util");

var common = require("../../../common/common.js").common;

const app = getApp();

// carmi/pages/details/details.js
Page({
    /**
   * 页面的初始数据
   */
    data: {
        details: [],
        page: 1
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        let that = this;
        wx.hideShareMenu();
        that.setData({
            status: Number(options.status),
            domain: app.globalData.domain.slice(0, -10)
        });
        that.getHistory();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {
        let that = this;
        that.setData({
            page: 1
        });
        that.getHistory();
    },
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {
        let that = this;
        that.getHistory();
    },
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    getHistory: function() {
        let that = this;
        common.request({
            endpoint: "/Exchange/exchange/history",
            method: "post",
            header: {},
            data: {
                model: that.data.status,
                page: that.data.page,
                limit: 10
            },
            success: function(res) {
                if (res.extra.length > 0) {
                    let details = that.data.page == 1 ? res.extra : that.data.details.concat(res.extra);
                    that.setData({
                        details: details,
                        page: that.data.page + 1
                    });
                }
            }
        });
    }
});